<?php

namespace App\Model\Ocean;

use App\Model\Model;
use App\Model\System\SystemFile;
use Hyperf\Database\Model\SoftDeletes;

/**
 * @property integer $id
 * @property string $name
 * @property string $picture
 * @property integer $create_time
 * @property integer $update_time
 * @property integer $delete_time
 */
class OceanFish extends Model
{
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'ocean_fish';

    public function picture()
    {
        return $this->hasOne(SystemFile::class, 'id', 'picture_id')->withDefault(function () {
            return App(SystemFile::class)->where('id', '455')->first();
        });
    }

    protected $fillable = [
        'id',
        'name',
        'picture_id',
        'price',
        'grow_time'
    ];

    protected $appends = [
        'grow_time_format'
    ];

    public function getGrowTimeFormatAttribute()
    {
        return $this->checkAttributes('grow_time', function ($grow_time) {
            return (int)($grow_time / 60) . '分钟';
        });
    }
}
